<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <h:head>
        <title>#{msgPool['system.homeName']}</title>
        
        <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
        <link type="text/css" rel="stylesheet" href="#{request.contextPath}/css/default.css" />
        <link type="text/css" rel="stylesheet" href="#{request.contextPath}/themes/black-tie/skin.css" />
        
        <style type="text/css">
            * { margin: 0; padding: 0; z-index: 1; }
            #limites { position: absolute; top: 28%; left: 45%; width: 720px; height: auto; margin: -200px 0 0 -340px; 
                       background-color: #eee; padding: 20px; }
        </style>
        <script type="text/javascript" src="#{request.contextPath}/js/padrao.js"></script>
       
        <script type="text/javascript"> 
            var $div1; var $div2; var $btn1;
            $(document).ready(function() {
                $div1 = jQuery('div[id*="' + accPanelJS.id + ':tabAdmSenhas"]');
                $div2 = jQuery('div[id*="' + accPanelJS.id + ':tabQuestionario"]');
                $btn1 = jQuery('button[id*="btnExecAcao"]');    
            });          
            function sucessAtlzAdmSenhas(xhr, status, args) { 
                if (args.isOkAdmSenhas)
                    tabAccordionOnOff(false); 
            }
            function handleCompRecSenha(xhr, status, args) { 
                if (args.onOffAdmSenhas)
                    tabAccordionOnOff(true); 
            }
            function tabAccordionOnOff(onOffAdmSenhas) {
                if (onOffAdmSenhas) {
                    //Desabilita: Administracao de senhas
                    $div1.disableSelection();
                    $div1.addClass("ui-state-disabled");
                    $div1.hide( "drop", { direction: "down" }, "fast" );
                    $btn1.prop('disabled', true);
                    slcOneMenuJS.disable();
                    //Habilita: Questionario
                    $div2.enableSelection();
                    $div2.removeClass("ui-state-disabled");
                    $div2.show( "fold", 1000 );
                }
                else { 
                    //Habilita: Administracao de senhas
                    jQuery('div[id*="recupSenhaForm:messages"]').find('.ui-messages-close').trigger('click');
                    $div1.enableSelection();
                    $div1.removeClass("ui-state-disabled");
                    $div1.show( "fold", 1000 );
                    $btn1.prop('disabled', false);
                    slcOneMenuJS.enable();
                    //Desabilita: Questionario
                    $div2.disableSelection();
                    $div2.addClass("ui-state-disabled");
                    $div2.hide( "drop", { direction: "down" }, "fast" );
                }
            } 
        </script>  
        
    </h:head>
    <h:body>
        
        <f:view locale="#{languageBean.localeCode}" />
            
        <h:form id="recupSenhaForm"> 
            
            <div id="limites"> 
                
                <p:growl id="growl" widgetVar="growl" showDetail="true" life="5000" severity="info" />
                <p:messages id="messages" globalOnly="true" showDetail="true" autoUpdate="true" closable="true" severity="warn, error" />                 
                <p:menubar> 
                    <p:menuitem value="#{msgLogin['I011']}" url="/login.jsf" icon="ui-icon-person" rendered="true" />  
                </p:menubar>     
              
                <p:accordionPanel style="text-align: center" widgetVar="accPanelJS">
                    <p:tab id="tabAdmSenhas" title="#{msgLogin['I201']}">
                        <p:focus for="username" />                    
                        <div align="center">                   
                            <h:panelGrid id="acaoRecupSenha" columns="3" >       
                                <h:outputLabel for="username" value="#{msgLogin['I007']}: *" style="float:right"/>
                                <p:inputText id="username" value="#{recuperarSenhaBean.username}" 
                                             required="true" label="#{msgLogin['I007']}" />
                                <p:message for="username" display="icon"/> 
                                <h:outputLabel for="password" value="#{msgLogin['I008']}:" style="float:right"/>
                                <p:password id="password" value="#{recuperarSenhaBean.password}" label="#{msgLogin['I008']}" />
                                <p:message for="password" display="icon"/>       
                                <h:outputLabel for="acao" value="#{msgPool['geral.I003']}: *" style="float:right" />  
                                <p:selectOneMenu  id="acao" value="#{recuperarSenhaBean.acao}" 
                                                  required="true" widgetVar="slcOneMenuJS" >  
                                    <f:selectItem itemLabel="#{msgPool['geral.I004']}" itemValue="" />  
                                    <f:selectItem itemLabel="#{msgLogin['I202']}" itemValue="1" />
                                    <f:selectItem itemLabel="#{msgLogin['I203']}" itemValue="2" />  
                                </p:selectOneMenu> 
                                <p:message for="acao" display="icon"/> 
                                <f:facet name="footer">
                                    <br />
                                    <h:panelGroup style="display:block; text-align:center">
                                        <p:commandButton id="btnExecAcao" value="#{msgPool['geral.I005']}" icon="ui-icon-check" 
                                                         actionListener="#{recuperarSenhaBean.acaoAdmSenhas}"
                                                         update="acaoRecupSenha, opcaoPerguntas, opcaoResposta"
                                                         oncomplete="handleCompRecSenha(xhr, status, args);"/>
                                    </h:panelGroup>
                                </f:facet>                        
                            </h:panelGrid>
                        </div>                        
                    </p:tab>
                    
                    <p:tab id="tabQuestionario" title="#{msgLogin['I204']}" disabled="true" >
                        <p:focus for="doctoCPF" />    
                        <div align="left">                 
                            <h:panelGrid id="opcaoPerguntas" columns="2" style="margin-bottom:10px" cellpadding="5">  
                                <h:outputLabel for="documento" value="#{msgLogin['I205']}: *" style="float:right"/>
                                <p:inputText id="doctoCPF" value="#{recuperarSenhaBean.nrDocumento}" label="#{msgLogin['I206']}" />                            
                                <h:outputText value="#{msgLogin['I207']}: *" style="float:right"/>  
                                <p:selectOneMenu id="perguntas" value="#{questionarioSenhaBean.questionario}" converter="questionarioSenha"  
                                        disabled="#{recuperarSenhaBean.acao eq '1' ? true : false}"
                                        panelStyle="width:230px" effect="fade" var="q" style="width:205px"  
                                        valueChangeListener="#{questionarioSenhaBean.questionarioChangeListener}" >
                                    <f:selectItem itemLabel="#{msgPool['geral.I004']}" itemValue="" />  
                                    <f:selectItems value="#{questionarioSenhaBean.questionarios}"  
                                                   itemLabel="" itemValue="#{questionarioSenha}"/>  
                                    <p:column><p:graphicImage value="/images/questionario/#{q.photoPergunta}" width="40" height="40"/></p:column>  
                                    <p:column>#{q.resumoPergunta}</p:column>  
                                    <p:ajax event="change" update="perguntaSelecionada" process="@this"/>
                                </p:selectOneMenu>  
                            </h:panelGrid>   
                            <br />
                            <h:panelGrid id="opcaoResposta" columns="1" style="margin-bottom:10px" cellpadding="5">                          
                                <p:inputText id="perguntaSelecionada" size="90" maxlength="90" readonly="true" style="font-weight:bold;"
                                    value="#{recuperarSenhaBean.acao eq '1' ? recuperarSenhaBean.pergunta : questionarioSenhaBean.questionario eq null ? '' : questionarioSenhaBean.questionario.pergunta}" />
                                <h:outputText value="&#160;"/> 
                                <p:inputText id="respPergunta" value="#{recuperarSenhaBean.resposta}" size="106" maxlength="100"/>
                                <h:outputText value="&#160;"/> 
                                <f:facet name="footer">
                                    <h:panelGroup style="display:block; text-align:center">
                                        <p:commandButton value="#{msgPool['geral.I005']}" icon="ui-icon-check"
                                                         process="tabQuestionario"
                                                         update="respPergunta, opcaoPerguntas"
                                                         oncomplete="sucessAtlzAdmSenhas(xhr, status, args);"
                                                         actionListener="#{recuperarSenhaBean.atlzAdmSenhas}" >
                                            <f:setPropertyActionListener target="#{recuperarSenhaBean.questionario}" value="#{questionarioSenhaBean.questionario}"/>     
                                        </p:commandButton> 
                                        <h:outputText value="&#160;&#160;&#160;"/>
                                        <p:commandButton type="button" value="#{msgPool['geral.I006']}" icon="ui-icon-close" 
                                                         onclick="tabAccordionOnOff(false)"/>  
                                    </h:panelGroup>
                                </f:facet>                        
                            </h:panelGrid>
                            <p:fieldset legend="#{msgPool['geral.I008']}" toggleable="true" toggleSpeed="500">  
                                <h:panelGrid columns="2" cellpadding="10">  
                                    <p:graphicImage value="/images/dock/email.png" />  
                                    <h:outputText value="#{msgLogin['I208']}"/> 
                                </h:panelGrid>  
                            </p:fieldset>                                 
                        </div>  
                    </p:tab>
                </p:accordionPanel>
                <!-- p:separator / --> 
             </div>
        </h:form>        
    </h:body>
</html>